<template>
  <div class="bar-container">
    <el-input
        class="powerInput"
        v-model="name"
        size="small"
        clearable
        placeholder="请输入电站名称"
    />
    <div 
        class="item" 
        v-for="(item, index) in filteredStationList" 
        :key="item.id" 
        :class="{ active: selectedItem === item.id }"
        @click="handleItemClick(item)" 
    >
        <div class="item-left">
            <span class="item-num">{{ (index + 1).toString().padStart(3, '0') }}</span> <!-- 格式化为三位数 -->
        </div>
        <div class="item-right">
            <div class="item-name">{{ item.name }}</div>
            <div class="item-name">{{ item.ENGname }}</div>
        </div>
    </div>
  </div>
</template>

<script>
import { deleteStationInfo, findStationPageList } from "@/api/PVManage";
export default {
  data() {
      return {
          name: '',
          stationList: [
            {
                id: 1,
                name: '电站1',
                ENGname: 'station1'
            },
            {
                id: 2,
                name: '电站2',
                ENGname: 'station2'
            },
            {
                id: 3,
                name: '电站3',
                ENGname: 'station3'
            },
          ],
          selectedItem: null,
          selectedItemData: null,
      }
  },
  created() {
      this.initData()
  },
  computed: {
    filteredStationList() {
      return this.stationList.filter(item => item.name.includes(this.name))
    }
  },
  methods: {
      initData() {
          findStationPageList().then(({ data }) => {
              this.stationList = data
              //展开后默认选择第一项
              if (this.stationList.length > 0) {
                  this.selectedItem = this.stationList[0]?.id
                  this.selectedItemData = this.stationList[0]
              }
              this.handleItemClick(this.selectedItemData)
          })
      },
      handleItemClick(item) {
        this.selectedItem = item.id
        this.selectedItemData = item // 赋值给selectedItemData
        this.$emit('item-click', item.id, item.name);
      },
  }
}
</script>

<style lang="scss" scoped>
    .bar-container {
        height:100%;
        overflow-y: auto;
        padding: 0 10px;

        background: linear-gradient(90deg, rgba(5, 59, 128, 1), rgba(1, 22, 57, 1));
        box-shadow: 0px 4px 8px 0px rgba(0,17,46,0.5);
        border: 1px solid rgba(0, 144, 242, 0.58); 
        // border-image: linear-gradient(270deg, rgba(5, 59, 128, 1), rgba(0, 62, 106, 1), rgba(1, 22, 57, 1), rgba(0, 144, 255, 1)) 1 1;
        border-radius: 10px;
    }
    .powerInput {
        margin-top: 12px;
        margin-bottom: 5px;
    }
    .item {
        margin-top: 10px;
        height: 60px;
        padding: 13px 0 0 18px;
        background: linear-gradient( 129deg, #00C3EE 0%, #0085F8 100%);
        cursor: pointer;
        display: flex;
        gap: 12px;
        border-radius: 2px;
        .item-num {
            height: 22px;
            font-family: PingFang SC, PingFang SC;
            font-weight: bold;
            font-size: 15px;
            color: #FFFFFF;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
        }
        .item-name {
            height: 22px;
            font-family: PingFang SC, PingFang SC;
            // font-weight: bold;
            font-weight: normal;
            font-size: 15px;
            color: #FFFFFF;
            line-height: 22px;
            text-align: left;
            font-style: normal;
            text-transform: none;
        }
        &:hover {
            color: #fff;
            background: #409eff !important;
        }
        &.active {
            color: #fff;
            background-color: #409eff;
        }
    }
    
</style>
